/**
 * 
 */
package com.google.code.netz.wfe.store;

import javax.persistence.EntityManager;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.google.code.netz.wfe.model.ICase;
import com.google.code.netz.wfe.model.Place;
import com.google.code.netz.wfe.model.Transition;
import com.google.inject.AbstractModule;
import com.google.inject.TypeLiteral;
import com.google.inject.matcher.Matchers;

/**
 * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
 * @version $Id: StoreModule.java 17 2009-02-09 13:08:49Z rahul.thakur.xdev $
 * @since 1.0
 */
public class StoreModule extends AbstractModule {

	/**
	 * Commons Logging.
	 */
	private static final Log log = LogFactory.getLog(StoreModule.class);

	private TransactionInterceptor txnInterceptor = new TransactionInterceptor();

	@Override
	protected void configure() {
		log.debug("Configuring module: " + StoreModule.class.getName());

		bind(EntityManager.class).toProvider(JpaProvider.class).asEagerSingleton();

		bindInterceptor(Matchers.any(), Matchers.annotatedWith(Transactional.class), txnInterceptor);

		bind(new TypeLiteral<Store<ICase, Query<ICase>>>() {
		}).to(new TypeLiteral<JpaStore<ICase, Query<ICase>>>() {
		});

		bind(new TypeLiteral<Store<Place, Query<Place>>>() {
		}).to(new TypeLiteral<JpaStore<Place, Query<Place>>>() {
		});

		bind(new TypeLiteral<Store<Transition, Query<Transition>>>() {
		}).to(new TypeLiteral<JpaStore<Transition, Query<Transition>>>() {
		});

		bind(TransactionInterceptor.class).toInstance(txnInterceptor);

		requestStaticInjection(StoreService.class);
	}
}
